//
//  MyHomeBtn.m
//  My_WeiBo
//
//  Created by Jay_Apple on 15/5/6.
//  Copyright (c) 2015年 Jay_Apple. All rights reserved.
//

#import "MyHomeBtn.h"
#import "NSString+getStringSize.h"

@implementation MyHomeBtn

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.contentMode = UIViewContentModeCenter;
        
        self.imageView.contentMode = UIViewContentModeLeft;
        
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        
//        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        self.adjustsImageWhenHighlighted = NO;
        
//        self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        
//        self.titleLabel.textColor = [UIColor colorWithHexString:@"#e4e4e4" alpha:1];

        
    }
    return self;
}

- (void)awakeFromNib{

    self.contentMode = UIViewContentModeCenter;
    
    self.imageView.contentMode = UIViewContentModeLeft;
    
    self.titleLabel.textAlignment = NSTextAlignmentRight;
    
    //        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    self.adjustsImageWhenHighlighted = NO;

}

//-(CGRect)imageRectForContentRect:(CGRect)contentRect{
//    
//    CGFloat imageY = 0;
//    CGFloat imageW = self.My_Height;
//    CGFloat imageX = self.My_Width - imageW + 4;
//    CGFloat imageH = self.My_Height;
//    return CGRectMake(imageX, imageY, imageW, imageH);
//
//}
//
//-(CGRect)titleRectForContentRect:(CGRect)contentRect{
//    
//    CGFloat titleY = 0;
//    CGFloat titleH = self.My_Height;
//    CGFloat titleW = self.My_Width - self.My_Height;
//    CGFloat titleX = 0;
//    return CGRectMake(titleX, titleY, titleW, titleH);
//
//}

//-(void)setTitle:(NSString *)title forState:(UIControlState)state{
//  
//    CGSize mysize = [title getStringSizewithStringsFont:self.titleLabel.font andMaxszie:CGSizeMake(300, 35)];
//    self.My_Height = mysize.height;
//    self.My_Width = mysize.width+self.My_Height;
//    [super setTitle:title forState:state];
//}

- (void)layoutSubviews{

    [super layoutSubviews];
    if (self.titleLabel.My_CenterX != self.My_Width * 0.5) {
        [self.titleLabel sizeToFit];
        self.titleLabel.My_CenterX = self.My_Width * 0.5;
        self.titleLabel.My_CenterY = self.My_Height * 0.5;
        self.imageView.My_X = CGRectGetMaxX(self.titleLabel.frame) + 5;
    }

}

@end
